import sys
import os
import subprocess

# Get args
target_day = sys.argv[1]
argv = sys.argv[2:]

# Find folder
target_folder = f'./{target_day}'
if os.path.exists(target_folder) == False:
    print(f'No \'{target_day}\' found')
    exit(-1)

# Compile
filenames = os.listdir(target_folder)
files = [ f'{target_folder}/{filename}' for filename in filenames ]
cc_files = [ file for file in files if file.endswith('.cc') ]
exe_file = f'./bin/{target_day}.exe'

compile_command = ['g++', '-o', exe_file] + cc_files
print(f'Compile: {cc_files}')
if subprocess.call(compile_command) != 0:
    exit(0)

# Run 
print(f'Run: [{exe_file}]')
subprocess.run(exe_file)